Variantenschnellauswahl
Mit diesem kleinen Gimmick stellen Sie dem Anwender eine Schnellauswahl der Varianten zur Verfügung. Ausserdem wird hier demonstriert, wie die Werte einer Variante übernommen werden können.
Die vorhandenen Varianten werden links am Rand angezeigt und können per Doppelklick übernommen werden. Auf Wunsch kann auch die Variante sofort ausgeführt werden.
Man könnte auch definieren, dass Varianten, die mit X beginnen, sofort ausgeführt werden, alle anderen werden nur geladen…
Desweiteren kann nachvollzogen werden, auf welch einfache Weise in Splitter mit ALV an ein Dynpro angebunden werden kann.
Ich habe den Report etwas auf Vordermann gebracht. Die alte Version hat mit dem Funktionsbaustein RS_VARIANT_CONTENTS und der manuellen Zuweisung der gespeicherten Variantenwerte über Feldsymbole gearbeitet. Die neue Version habe ich einerseits auf Methoden umgestellt und zudem verwende ich den Funktionsbaustein RS_SUPPORT_SELECTIONS, der die Übernahme der Feldwerte in das Dynpro automatisch macht.
Coding – Aktuelle Variante
REPORT. PARAMETERS p_eins TYPE char10. PARAMETERS p_zwei TYPE char10. CLASS main DEFINITION. PUBLIC SECTION. METHODS handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column. METHODS load_variants. METHODS reload_variants. METHODS get_variant IMPORTING variant_name TYPE raldb_vari. METHODS refresh. PROTECTED SECTION. DATA docker TYPE REF TO cl_gui_docking_container. DATA alv TYPE REF TO cl_gui_alv_grid. DATA fcat TYPE lvc_t_fcat. DATA layout TYPE lvc_s_layo. DATA varit TYPE STANDARD TABLE OF varit. ENDCLASS. "lcl_event_receiver DEFINITION CLASS main IMPLEMENTATION. METHOD handle_double_click. FIELD-SYMBOLS <varit> TYPE varit. READ TABLE varit ASSIGNING <varit> INDEX e_row. IF sy-subrc = 0. "Read Variant and assign values get_variant( <varit>-variant ). "Set variant name sy-slset = <varit>-variant. *** execute program (activate to your own needs) * CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE' * EXPORTING * functioncode = '=ONLI'. ENDIF. ENDMETHOD. "handle_double_click METHOD load_variants. " get all variants and texts SELECT * FROM varit INTO TABLE varit WHERE langu = sy-langu AND report = sy-repid. CHECK sy-subrc = 0. " Create docking container on left side docker = NEW #( side = cl_gui_docking_container=>dock_at_left extension = 350 ). " Create ALV-Grid alv = NEW #( i_parent = docker i_appl_events = 'X' ). " Create event receiver for double click in grid SET HANDLER handle_double_click FOR alv. " Define ALV-Grid-Layout layout-no_toolbar = 'X'. layout-grid_title = 'Auswahl mit Doppelklick…'(001). layout-smalltitle = 'X'. " Display ALV Grid alv->set_table_for_first_display( EXPORTING i_structure_name = 'VARIT' i_save = space i_default = 'X' is_layout = layout CHANGING it_outtab = varit EXCEPTIONS OTHERS = 4 ). " Get frontend catalog to modify alv->get_frontend_fieldcatalog( IMPORTING et_fieldcatalog = fcat ). " modify fields LOOP AT fcat ASSIGNING FIELD-SYMBOL(<fcat>). CASE <fcat>-fieldname. WHEN 'MANDT' OR 'REPORT' OR 'LANGU'. <fcat>-tech = 'X'. WHEN 'VARIANT'. <fcat>-outputlen = '10'. ENDCASE. ENDLOOP. " set modified field catalog alv->set_frontend_fieldcatalog( fcat ). " Refresh display to activate catalog refresh( ). ENDMETHOD. METHOD refresh. IF alv IS BOUND. alv->refresh_table_display( ). ENDIF. ENDMETHOD. METHOD get_variant. "Activate selected variant CALL FUNCTION 'RS_SUPPORT_SELECTIONS' EXPORTING report = sy-cprog variant = variant_name EXCEPTIONS OTHERS = 3. ENDMETHOD. METHOD reload_variants. " set variant CONCATENATE 'Gewählte Variante:' sy-slset INTO DATA(vartx) SEPARATED BY space. IF sy-msgid = 'DB'. IF sy-msgno = '617'. " variant has been saved READ TABLE varit TRANSPORTING NO FIELDS WITH KEY variant = sy-slset. IF sy-subrc > 0. SELECT * FROM varit APPENDING TABLE varit WHERE langu = sy-langu AND report = sy-repid AND variant = sy-slset. SORT varit BY variant. " Refresh display to activate catalog refresh( ). ENDIF. ENDIF. IF sy-msgno = '618'. " Variant deleted DELETE varit WHERE variant = sy-msgv1. " Refresh display to activate catalog refresh( ). ENDIF. ENDIF. ENDMETHOD. ENDCLASS. INITIALIZATION. DATA(go_main) = NEW main( ). go_main->load_variants( ). AT SELECTION-SCREEN OUTPUT. go_main->reload_variants( ). " Start of program START-OF-SELECTION. WRITE: / 'P_EINS:', p_eins. WRITE: / 'P_ZWEI:', p_zwei.
Coding – Alte Variante
REPORT zz_var_grid. *** Docking container and ALV Grid to display variants DATA gr_docking TYPE REF TO cl_gui_docking_container. DATA gr_alv TYPE REF TO cl_gui_alv_grid. DATA gt_fcat TYPE lvc_t_fcat. FIELD-SYMBOLS TYPE lvc_s_fcat. DATA gs_layo TYPE lvc_s_layo. DATA gt_varit TYPE STANDARD TABLE OF varit. CLASS lcl_event_receiver DEFINITION DEFERRED. DATA gr_event_receiver TYPE REF TO lcl_event_receiver. SELECTION-SCREEN BEGIN OF BLOCK var WITH FRAME TITLE gv_vartx. PARAMETERS p_1. SELECTION-SCREEN END OF BLOCK var. *----------------------------------------------------------------------* * CLASS lcl_event_receiver DEFINITION *----------------------------------------------------------------------* CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column. ENDCLASS. "lcl_event_receiver DEFINITION *----------------------------------------------------------------------* * CLASS lcl_event_receiver IMPLEMENTATION *----------------------------------------------------------------------* CLASS lcl_event_receiver IMPLEMENTATION. METHOD handle_double_click. FIELD-SYMBOLS TYPE varit. READ TABLE gt_varit ASSIGNING INDEX e_row. IF sy-subrc = 0. *** Read Variant and assign values PERFORM get_variant USING -variant. *** Set variant name sy-slset = -variant. *** execute program (activate to your own needs) * CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE' * EXPORTING * functioncode = '=ONLI'. ENDIF. ENDMETHOD. "handle_double_click ENDCLASS. "lcl_event_receiver IMPLEMENTATION AT SELECTION-SCREEN OUTPUT. *** set variant CONCATENATE 'Gewählte Variante:' sy-slset INTO gv_vartx SEPARATED BY space. IF sy-msgid = 'DB'. IF sy-msgno = '617'. *** variant has been saved READ TABLE gt_varit TRANSPORTING NO FIELDS WITH KEY variant = sy-slset. IF sy-subrc > 0. SELECT * FROM varit APPENDING TABLE gt_varit WHERE langu = sy-langu AND report = sy-repid AND variant = sy-slset. SORT gt_varit BY variant. *** Refresh display to activate catalog CALL METHOD gr_alv->refresh_table_display. ENDIF. ENDIF. IF sy-msgno = '618'. *** Variant deleted DELETE gt_varit WHERE variant = sy-msgv1. *** Refresh display to activate catalog CALL METHOD gr_alv->refresh_table_display. ENDIF. ENDIF. INITIALIZATION. *** get all variants SELECT * FROM varit INTO TABLE gt_varit WHERE langu = sy-langu AND report = sy-repid. CHECK sy-subrc = 0. *** Create docking container on left side CREATE OBJECT gr_docking EXPORTING side = cl_gui_docking_container=>dock_at_left extension = 350. *** Create ALV-Grid CREATE OBJECT gr_alv EXPORTING i_parent = gr_docking i_appl_events = 'X'. *** Create event receiver for double click in grid CREATE OBJECT gr_event_receiver. SET HANDLER gr_event_receiver->handle_double_click FOR gr_alv. *** Define ALV-Grid-Layout gs_layo-no_toolbar = 'X'. gs_layo-grid_title = 'Auswahl mit Doppelklick...'(001). gs_layo-smalltitle = 'X'. *** Display ALV Grid CALL METHOD gr_alv->set_table_for_first_display EXPORTING i_structure_name = 'VARIT' i_save = space i_default = 'X' is_layout = gs_layo CHANGING it_outtab = gt_varit EXCEPTIONS OTHERS = 4. *** Get frontend catalog to modify CALL METHOD gr_alv->get_frontend_fieldcatalog IMPORTING et_fieldcatalog = gt_fcat. *** modify fields LOOP AT gt_fcat ASSIGNING . CASE -fieldname. WHEN 'MANDT' OR 'REPORT' OR 'LANGU'. -tech = 'X'. WHEN 'VARIANT'. -outputlen = '10'. ENDCASE. ENDLOOP. *** set modified field catalog CALL METHOD gr_alv->set_frontend_fieldcatalog EXPORTING it_fieldcatalog = gt_fcat. *** Refresh display to activate catalog IF gr_alv IS BOUND. CALL METHOD gr_alv->refresh_table_display. ENDIF. *** Start of program START-OF-SELECTION. WRITE: / 'Variante', gv_vartx. WRITE: / 'P1:', p_1. *&---------------------------------------------------------------------* *& Form get_variant *&---------------------------------------------------------------------* FORM get_variant USING iv_varid TYPE variant. DATA lt_valutab LIKE rsparams OCCURS 0 WITH HEADER LINE. DATA lt_objects LIKE vanz OCCURS 0 WITH HEADER LINE. DATA lv_seltab(20). FIELD-SYMBOLS TYPE STANDARD TABLE. FIELD-SYMBOLS TYPE ANY. FIELD-SYMBOLS TYPE ANY. *** get contents of variant CALL FUNCTION 'RS_VARIANT_CONTENTS' EXPORTING report = sy-cprog variant = iv_varid no_import = ' ' execute_direct = ' ' TABLES valutab = lt_valutab OBJECTS = lt_objects EXCEPTIONS variant_non_existent = 01 variant_obsolete = 02. IF sy-subrc > 0. *** Error MESSAGE e000(oo) WITH 'Variante nicht vorhanden:' iv_varid. ELSE. *** Clear old values LOOP AT lt_objects. *** -> workarea ASSIGN (lt_objects-name) TO . IF sy-subrc = 0. CLEAR . ENDIF. IF lt_objects-kind = 'S'. *** -> table CONCATENATE lt_objects-name '[]' INTO lv_seltab. ASSIGN (lv_seltab) TO . IF sy-subrc = 0. CLEAR . ENDIF. ENDIF. *** Assign values of variant LOOP AT lt_valutab WHERE selname = lt_objects-name. *** -> Workarea ASSIGN (lt_valutab-selname) TO . CHECK sy-subrc = 0. CASE lt_objects-kind. WHEN 'S'. *** *** SELECT-OPTIONS *** *** -> table CONCATENATE lt_valutab-selname '[]' INTO lv_seltab. ASSIGN (lv_seltab) TO . CHECK sy-subrc = 0. *** -> SIGN ASSIGN COMPONENT 'SIGN' OF STRUCTURE TO . IF sy-subrc = 0. = lt_valutab-sign. ENDIF. *** -> OPTION ASSIGN COMPONENT 'OPTION' OF STRUCTURE TO . IF sy-subrc = 0. = lt_valutab-option. ENDIF. *** -> LOW ASSIGN COMPONENT 'LOW' OF STRUCTURE TO . IF sy-subrc = 0. = lt_valutab-low. ENDIF. *** -> HIGH ASSIGN COMPONENT 'HIGH' OF STRUCTURE TO . IF sy-subrc = 0. = lt_valutab-high. ENDIF. APPEND TO . WHEN 'P'. *** *** PARAMETER *** = lt_valutab-low. ENDCASE. ENDLOOP. ENDLOOP. ENDIF. ENDFORM. "get_variant
- 7. December: Excel Racing Simulation – Root Vole Race - 7. Dezember 2024
- 5. December: ABAPConf - 5. Dezember 2024
- 4. December: Only a lazy developer is a good developer - 4. Dezember 2024